var searchInsert = function (nums, target) {
  let index =  nums.indexOf(target)
  if(index > 0) return index
  else {
    function ways(a,b) {
        return a - b
    }

      nums.push(target)
     let arr =  nums.sort(ways)
     console.log(arr);
      console.log( arr.indexOf(target));
  }
};
searchInsert([3, 5, 7,9,10], 8)